#! -*- encoding: utf-8 -*-
# Create your views here.
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import md5
import logging
import settings
import models


global current_status
current_status= models.Status.objects.get(id=settings.init_status_id)

class Input:
    def __init__(self, scheme, path, query, method, body, headers):
        self.scheme = scheme
        self.path = path
        self.query = query
        self.method = method
        self.body = body
        self.headers = headers

    def get_id(self):
        credential = self.__str__()
        p = md5.md5(credential).hexdigest()
        logging.debug("digest = %s", p)
        return p

    def __str__(self):
        return ".".join(map(str, [self.scheme, self.path, self.query, self.method, self.body, self.headers]))


class Output:
    pass

@csrf_exempt
def get_response(request):
    # 获取各种输入
    i = Input(scheme="http",
              path=request.path,
              query=request.REQUEST,
              method=request.method,
              body=request.raw_post_data,
              headers="")

    # 获取各种输出
    content = i.get_id() + "**********" + str(i)
    mimetype = None
    status = None
    content_type = None
    response = HttpResponse(content, mimetype, status, content_type)
    return response
